{include file="public/layout" /}

<body>

<link rel="stylesheet" href="__SKIN__/css/page.css" media="all">

<div class="layui-fluid layui-form " id="LAY-component-layer-list">
    <div class="layui-card">
        <div class="head-oper">
            <div class="fl ">
			 {eq name="$Think.const.CONTROLLER_NAME.'@add'|is_check_access" value="1"}
				{gt name="$typeid" value="0"}
				<a data-typeid="{$typeid}" data-url="{:url('Archives/add')}" onclick="customvar_add(this)" id="customvar_add" class="layui-btn mt5 ">
				发布文档
				</a>
				{else /}
				<a href="javascript:void(0);" onClick="quick_release()" class="layui-btn mt5">
				发布文档
				</a>
				{/gt}


				<!--<a href="javascript:void(0);" onClick="{gt name="$Request.param.typeid" value="0"}window.location.href='{:url("Archives/add", array("typeid"=>$Request.param.typeid))}';{else /}quick_release();{/gt}" class="layui-btn mt5">-->
				<!--发布文档-->
				<!--</a>-->
				{/eq}
            
              
            </div>
            <div class="fr">
                <div class="fl mt5 mr5" >
					<div class="layui-input-inline w100">
						<select name="typeid123" id="typeid" lay-ignore>
							<option value="">选择栏目</option>
							{$arctype_html}
						</select>
					</div>
				</div>
				<div class="fl mt5" >
					<div class="layui-input-inline w200">
						<input type="text" name="keywords" id="keywords"  value="{$Request.param.keywords}" placeholder="搜索"  class="layui-input">
					</div>
				</div>
				<div class="layui-input-inline w50 layadmin-layer-demo mt5">
					<button class="layui-btn input-btn-search" data-type="search"><i class="layui-icon layui-icon-search"></i></button>
				</div>
            </div>
        </div>

        <div class="nav-left">
      


		<div class="main dynamic-navigation">
			{eq name="$typeid" value="0}
			<div id="view1">
				<div class="layui-card-body">
					<div class="empty-show">
						<p>点击左侧栏目列表管理内容</p>
						<select name="typeid" id="typeid"  lay-ignore="" onchange="settypeid(this)">
							<option value="">请选择栏目</option>
							{$arctype_html}
						</select>
					</div>
				</div>
			</div>
			{/eq}
 		</div>
    </div>
</div>

<script>
    var laypageNew;
    var formNew;
    var tableNew;
    $(function () {
        var aids = '';
        var openurl = "{$Request.param.openurl}";
        var msg = "{$Request.param.msg}";
        var typeid = "{$typeid}";
        var url_table = "{$url_table}";
        if (typeid > 0){
            set_right_table(url_table,typeid,1);
        }
        if (openurl){
            var iframes = layer.open({
                type: 2,
                title: msg+'文档',
                fixed: true, //不固定
                shadeClose: false,
                shade: 0.3,
                content: openurl
            });
            layer.full(iframes);
        }
    });
    layui.config({
        base: '__SKIN__/' //静态资源所在路径
        ,version: '{$version}'
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','form','laypage', 'table','layedit'], function(){
        var $ = layui.$
            ,layedit = layui.layedit
            ,laypage= laypageNew = layui.laypage
            ,form = formNew = layui.form
            ,table = tableNew = layui.table;

        reload();

        /* 触发事件 */
        var active = {
            search:function () {        //触发搜索事件（重载数据列表）
                var typeid = $("#typeid").val() //获取起始页
                var table_url =  $("#table_url").val();
				if (table_url){
                    var keywords = $("#keywords").val();
                    table_url = table_url + "&keywords=" + keywords;
                    set_right_table(table_url,typeid,0);
				}
            }
        };
        $('#LAY-component-layer-list .layadmin-layer-demo .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] && active[type].call(this);
        });

        //监听提交(单页内容提交)
        form.on('submit(formSubmit)', function(data){
            var load = layer_loading();
            data.field._ajax = 1;
            $.ajax({
                type : 'post',
                url : "{:url('Arctype/single_edit')}",
                data : data.field,
                dataType : 'json',
                success : function(res){
                    layer.close(load); //关闭loading
                    if(res.code == 1){
                        layer.msg(res.msg, {icon: 1, time: 1000}, function(){

                        });
                    }else{
                        layer.msg(data.msg, {icon: 2,time: 2000});
                    }
                },
                error: function(e){
                    layer.close(load); //关闭loading
                    showErrorAlert();
                }
            });
            return false;
        });
        //开启关闭
        form.on('switch(is_recom)', function(obj){
            var dataid = $(this).data('id');
            if ($(this).val() == 1){
                $(this).val(0);
            }else{
                $(this).val(1);
            }
            changeTableVal('archives','aid',dataid,'is_recom',this);
        });
        //全选
        form.on('checkbox(checkAll)', function(data){
            var a = data.elem.checked;
            $('input[name*=ids]').prop('checked',a);
            form.render('checkbox');
        });
    });
    //设置默认栏目
	function settypeid(obj){
	    if (obj.value > 0){
            $.ajax({
                url: "{:url('Admin/ajax_settypeid')}",
                type: 'POST',
                dataType: 'JSON',
                async: false,
                data: {typeid:obj.value,_ajax:1},
                success: function(res){
                    if(res.code == 1){
                        location.reload();
                    }else{
                        layer.msg(data.msg, {icon: 2,time: 2000});
                    }
                },
                error: function(e){
                    showErrorMsg();
                    return false;
                }
            });
		}
	}
    //重新加载
	function reload(){
        laypageNew.render({
            elem: 'pages'
            ,count: $("#count").val() //数据总数
            ,limit: $("#limit").val()
            ,curr: $("#curr").val() //获取起始页
            ,jump: function(obj, first){
                if (!first){
                    var typeid = $("#typeid").val() //获取起始页
                    var table_url =  $("#table_url").val();
                    var keywords = $("#keywords").val();
                    table_url = table_url+"&p="+obj.curr + "&keywords=" + keywords;
                    set_right_table(table_url,typeid,0);
                }
            }
        });
        formNew.render();
	}
	//点击左边触发更新右边
	function set_right(obj) {
        var typeid = $(obj).data('typeid');
        var urltable = $(obj).data('urltable');
        var channel = $(obj).data('channel');
        $("#customvar_add").data("typeid",typeid);
        if (channel == 6){
            $("#customvar_add").hide();
		}else{
            $("#customvar_add").show();
		}
		//设置当前为选中状态，并且清除筛选条件
        $(".ononon").attr('id','')
        $(obj).attr("id",'ononon');
		//渲染右边
        set_right_table(urltable+"&channel="+channel,typeid,0);
    }
	//渲染右边列表
	function set_right_table(url,typeid,first) {
        if (first < 1){
            var load = layer_loading();
        }
        $.ajax({
            url: url,
            type: 'POST',
            dataType: 'JSON',
            async: false,
            data: {typeid:typeid,_ajax:1},
            success: function(res){
                $(".main").html(res);
                if (first < 1){
                    layer.close(load); //关闭loading
                    reload();

				}
            },
            error: function(e){
                if (first < 1){
                    layer.close(load); //关闭loading
                }
                showErrorAlert();
                return false;
            }
        });
    }
    //添加
	function customvar_add(obj) {
	    var url = $(obj).data('url');
	    var typeid = $(obj).data('typeid');
        var iframes = layer.open({
            type: 2,
            title: '新增文档',
            fixed: true, //不固定
            shadeClose: false,
            shade: 0.3,
            content: url+"&typeid="+typeid
        });
        layer.full(iframes);
    }
    //编辑
	function customvar_edit(obj) {
        var iframes = layer.open({
            type: 2,
            title: '编辑文档',
            fixed: true, //不固定
            shadeClose: false,
            shade: 0.3,
            content: $(obj).data('url')
        });
        layer.full(iframes);
    }
    //发布文档(无栏目id时)
    function quick_release()
    {
        //iframe窗
        layer.open({
            type: 2,
            title: '快捷发布文档',
            fixed: true, //不固定
            shadeClose: false,
            shade: 0.3,
            maxmin: true, //开启最大化最小化按钮
            area: ['600px', '520px'],
            content: "//{$Request.host}{$Request.baseFile}?m=admin&c=Archives&a=release&iframe=2",
            success: function(layero, index){

            }
        });
    }

    //批量移动
    function func_move(obj, name)
    {
        var a = [];
        var k = 0;
        aids = '';
        $('input[name^='+name+']').each(function(i,o){
            if($(o).is(':checked')){
                a.push($(o).val());
                if (k > 0) {
                    aids += ',';
                }
                aids += $(o).val();
                k++;
            }
        })
        if(a.length == 0){
            layer.alert('请至少选择一项', {icon: 2, title:false});
            return;
        }

        var url = $(obj).data('url');
        //iframe窗
        layer.open({
            type: 2,
            title: '批量移动',
            fixed: true, //不固定
            shadeClose: false,
            shade: 0.3,
            maxmin: false, //开启最大化最小化按钮
            area: ['350px', '260px'],
            content: url
        });
    }

    //批量复制
    function func_batch_copy(obj, name)
    {
        var a = [];
        var k = 0;
        aids = '';
        $('input[name^='+name+']').each(function(i,o){
            if($(o).is(':checked')){
                a.push($(o).val());
                if (k > 0) {
                    aids += ',';
                }
                aids += $(o).val();
                k++;
            }
        })
        if(a.length == 0){
            layer.alert('请至少选择一项', {icon: 2, title:false});
            return;
        }

        var url = $(obj).data('url');
        //iframe窗
        layer.open({
            type: 2,
            title: '批量复制',
            fixed: true, //不固定
            shadeClose: false,
            shade: 0.3,
            maxmin: false, //开启最大化最小化按钮
            area: ['350px', '260px'],
            content: url
        });
    }
    /**
     * 获取修改之前的内容
     */
    function get_aids()
    {
        return aids;
    }
	 //内容导航
	  $(".on-off").click(function () {
		  
		 var a = $('.dynamic-navigation');
		
		a && (a.attr("tg") ? (a.animate({
			left: 20,
			opacity: "show"
		}, 500), a.removeAttr("tg")) : (a.animate({
			left: -200,
			opacity: "show"
		}, 500), a.attr("tg", "1")))
		  
		if ($(this).children('i').hasClass("layui-icon-left")) {
			
		    $(this).children('i').removeClass("layui-icon-left");
		    $(this).children('i').addClass("layui-icon-right");
			
			
		} else if ($(this).children('i').hasClass("layui-icon-right")) {
			
			$(this).children('i').removeClass("layui-icon-shrink-right");
			$(this).children('i').addClass("layui-icon-left");
		}
		  
		})
</script>
{include file="public/footer" /}
